Repository navigation
Make Java code model companion members static - #100
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Annotate the caller-facing companion members of `ClassName`, `JavaTypeName`, `TypeVariableName`, and `FieldMethods` with `@JvmStatic`, so that Java code calls them as `ClassName.guess(...)`, `JavaTypeName.getKnownPrimitives()`, etc. The `Companion` accessors remain, keeping the change binary- and source-compatible. Build `JavaTypeName.KnownPrimitives` lazily. It used to be computed in the static initializer of `JavaTypeName`, which put `null` into the list when a primitive type object, such as `JavaTypeName.INT`, was initialized before `JavaTypeName` itself. Add `XJavaSpec` suites for the Java access and a fresh-JVM regression test for the initialization order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
There was a problem hiding this comment.
🟢 Approved
No active review issues are reported for the changes simplifying Java access to the compiler’s JVM code model.
No open issues 🎉
What changed in this PR
This PR simplifies Java access to the compiler’s JVM code model, supporting core-jvm-compiler’s migration from JavaPoet while retaining existing companion accessors.
Changes:
- Adds
@JvmStaticto caller-facing companion members and Java tests covering both access styles. - Lazily initializes known primitives to prevent null entries, with a fresh-JVM regression test.
- Updates API documentation, bumps the version to
2.0.0-SNAPSHOT.083, and refreshes dependency reports.
| File | Description |
|---|---|
version.gradle.kts |
Bumps the compiler snapshot version. |
jvm/src/test/kotlin/io/spine/tools/compiler/jvm/JavaTypeNameSpec.kt |
Adds the primitive-first initialization regression test. |
jvm/src/test/kotlin/io/spine/tools/compiler/jvm/given/PrimitiveFirstProgram.kt |
Checks the primitive list after accessing INT first. |
jvm/src/test/kotlin/io/spine/tools/compiler/jvm/given/JvmRun.kt |
Provides isolated JVM execution using a manifest classpath. |
jvm/src/test/java/io/spine/tools/compiler/jvm/TypeVariableNameJavaSpec.java |
Tests static and companion type-variable accessors. |
jvm/src/test/java/io/spine/tools/compiler/jvm/JavaTypeNameJavaSpec.java |
Tests static and companion primitive-list accessors. |
jvm/src/test/java/io/spine/tools/compiler/jvm/FieldMethodsJavaSpec.java |
Tests static and companion getter-name generation. |
jvm/src/test/java/io/spine/tools/compiler/jvm/ClassNameJavaSpec.java |
Tests Java access to factories, regex, and constants. |
jvm/src/main/kotlin/io/spine/tools/compiler/jvm/TypeVariableName.kt |
Exposes static getters for T and E and documents them. |
jvm/src/main/kotlin/io/spine/tools/compiler/jvm/JavaTypeName.kt |
Adds static primitive-list access and lazy initialization. |
jvm/src/main/kotlin/io/spine/tools/compiler/jvm/FieldConventions.kt |
Exposes getterOf() as a static Java method. |
jvm/src/main/kotlin/io/spine/tools/compiler/jvm/ClassName.kt |
Adds static companion access and closes a KDoc code fence. |
docs/dependencies/pom.xml |
Updates the reported compiler version. |
docs/dependencies/dependencies.md |
Refreshes report versions and generation timestamps. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR makes the caller-facing companion members of the Java code model in
io.spine.tools.compiler.jvmcallable from Java without.Companion, using@JvmStatic:ClassName.Companion.guess(name)ClassName.guess(name)ClassName.Companion.getSimpleNameRegex()ClassName.getSimpleNameRegex()JavaTypeName.Companion.getKnownPrimitives()JavaTypeName.getKnownPrimitives()TypeVariableName.Companion.getT()/getE()TypeVariableName.getT()/getE()FieldMethods.Companion.getterOf(name, cardinality)FieldMethods.getterOf(name, cardinality)@JvmStaticwas chosen over@JvmFieldbecause it keeps theCompanionaccessors, so the change is binary- and source-compatible.javapon the built jar shows both the new static methods and the unchangedX$Companionmethods. TheClassName.*_SEPARATORconstants areconst valand were already static.Why
core-jvm-compiler is replacing JavaPoet with the Compiler's Java code model. Its Java sources (
FieldTypeand related classes) had to callClassName.Companion.guess(...)andJavaTypeName.Companion.getKnownPrimitives(). This PR fixes that at the source.Bug fix:
JavaTypeName.KnownPrimitivescould containnullThe list used to be built in the static initializer of
JavaTypeName. Per JVMS §5.5, when a nested primitive object such asJavaTypeName.INTis initialized beforeJavaTypeName, the outer initializer readsINT.INSTANCEwhile it is stillnull. A fresh JVM produced[void, boolean, byte, short, null, long, char, float, double].The list is now built
by lazy. The public getters are unchanged; only a private backing field changed.Tests
XJavaSpecsuites injvm/src/test/java/(ClassNameJavaSpec,JavaTypeNameJavaSpec,TypeVariableNameJavaSpec,FieldMethodsJavaSpec). They call each member both statically and throughCompanion.JavaTypeNameSpecruns a program in a fresh JVM (given/JvmRun.kt,given/PrimitiveFirstProgram.kt). The program touchesINTfirst and checks the whole list. The test failed before the fix and passes after it. It usesProcessBuilderrather than reflection, and passes the classpath via a manifest-only JAR so the command line stays short on Windows CI.Reviewer notes
ClassName.clazzis now closed, andTypeVariableName.T/Egot KDoc.EnumName.guess(...), which returns aClassName. A Java subclass that declares an instance method with the same signature would no longer compile. No such subclasses exist invalidationorcore-jvm-compiler.annotation/andstyle/sub-packages (SuppressWarningsAnnotation.ALL_WARNINGS,ModifiedTypeAnnotation.currentDateTime(),PsiJavaCodeStyleFormatter.settingsId).Version
The version is bumped to
2.0.0-SNAPSHOT.083, and the dependency reports are regenerated. A clean./gradlew build dokkaGenerate publishToMavenLocalpasses locally.🤖 Generated with Claude Code